package com.cloud.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.common.entity.ShopOrder;
import com.cloud.order.service.ShopOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author 李均华
 * @since 2021-06-04
 */
@RestController
@RequestMapping("/shop/order")
public class ShopOrderController {

    @Autowired
    private ShopOrderService shopOrderService;

    /**
     * 用户下单
     * @param id 商品id
     * @param num 商品数量
     * @return
     */
    @GetMapping("order/{id}/{num}")
    public ShopOrder order(@PathVariable Integer id, @PathVariable Integer num) {
        ShopOrder shopOrder = new ShopOrder()
                .setShopProductId(id)
                .setNum(num);
        shopOrderService.save(shopOrder);
        return shopOrder;
    }

    /**
     * 分页查询
     * @return
     */
    @GetMapping("/page")
    public IPage<ShopOrder> page(){
        Page<ShopOrder> page = new Page<>();
        return shopOrderService.page(page);
    }
}

